<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>表格的隔行变色</title>
   <script>
     window.onload=function(){
	    var oTab=document.getElementById("tab1");
		var oldColor="";
	  //  alert(oTab.tBodies[0].rows[1].cells[0].innerHTML);
        for(var i=0;i<oTab.tBodies[0].rows.length;i++){
		
		    oTab.tBodies[0].rows[i].onmouseover=function(){
			   oldColor=this.style.background;
			   this.style.background="blue";
			};
            oTab.tBodies[0].rows[i].onmouseout=function(){
			   this.style.background=oldColor;
			};			
		    if(i%2){
			  oTab.tBodies[0].rows[i].style.background="";			
			}else{
			   oTab.tBodies[0].rows[i].style.background="green";
			}		
		}		
	 };
   </script>
</head>
<body>
   <table id="tab1" border="1" width="500">
     <thead>
	    <td>ID</td>
	    <td>姓名</td>
	    <td>年龄</td>
     </thead>
	   <tr><td>1</td><td>Blue</td><td>23</td></tr>
	   <tr><td>2</td><td>Blue</td><td>23</td></tr>
	   <tr><td>3</td><td>Blue</td><td>23</td></tr>
	   <tr><td>4</td><td>Blue</td><td>23</td></tr>
	   <tr><td>5</td><td>Blue</td><td>23</td></tr>
	 <tbody>
     </tbody>
   </table>


</body>
</html>